/* 
 *  Copyright 2012 CodeMagi, Inc.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.codemagi.servlets.model.comparators;

import com.codemagi.servlets.model.Node;
import java.util.Comparator;

/**
 * Comparator used for sorting Nodes by descending date (newer items first)
 */
public class NodeCreatedDateDescendingSort implements Comparator {

    @Override
    public int compare(Object o1, Object o2) {

	int output = 0;
	
	try {
	    Node n1 = (Node)o1;
	    Node n2 = (Node)o2;
	    
	    output = n2.getCreatedDate().compareTo( n1.getCreatedDate() );
		
	} catch (Exception e) {
	    //NullPointerException, ClassCastException, for example                             
	}
	
	return output;
    }
}
